//
//  OrderConfirmViewController.m
//  Lmm_IOS
//
//  Created by 张哲炜 on 2018/10/16.
//  Copyright © 2018 lmm. All rights reserved.
//

#import "OrderConfirmViewController.h"

@interface OrderConfirmViewController ()

@end

@implementation OrderConfirmViewController{
    
     UIView *navView;
    
    UITextField *_mobileTextField;
    UITextField *_consigneeTextField;
    UILabel *_areaLabel;
    UITextView *_addressTextView;
    
    UIView *_pickerViewArea;
    UIPickerView *_pickerView;
    UIButton *_maskButton;
    
    NSArray *_provinceArray;
    NSArray *_cityArray;
    NSDictionary *_districtDic;
    
    NSString *_province;
    NSString *_city;
    NSString *_district;
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColorFromRGB(0xEEEEEE);
    
    [self initPickerData];
    
    self->navView = UIView.new;
    self->navView.backgroundColor = [UIColor whiteColor];
    
    int height = NAVIGATION_BAR_HEIGHT;
    int titleLabelOffset = 20;
    if (DEVICE_IS_IPHONEX) {
        height = NAVIGATION_BAR_X_HEIGHT;
        titleLabelOffset = 40;
    }
    
    [self.view addSubview:navView];
    
    [navView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.top).offset(0);
        make.left.equalTo(self.view.left).offset(0);
        make.right.equalTo(self.view.right).offset(0);
        make.height.equalTo(height);
    }];
    
    
    UIView *divideLine = UIView.new;
    divideLine.backgroundColor =UIColorFromRGB(0xCCCCCC) ;
    [navView addSubview:divideLine];
    
    [divideLine makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->navView.bottom);
        make.left.equalTo(self.view.left).offset(0);
        make.right.equalTo(self.view.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    
    UIImageView *backImage = UIImageView.new;
    backImage.image = [UIImage imageNamed:@"back"];
    [navView addSubview:backImage];
    
    [backImage makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->navView.left).offset(15);
        make.top.equalTo(self->navView.top).offset(height-30);
        make.width.equalTo(10);
        make.height.equalTo(18);
    }];
    
    
    
    UIButton *backbtn = UIButton.new;
    [backbtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backbtn];
    
    [backbtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->navView.left).offset(10);
        make.top.equalTo(self->navView.top).offset(20);
        make.width.equalTo(50);
        make.height.equalTo(40);
    }];
    
    
    UILabel *title = UILabel.new;
    title.textColor = [UIColor blackColor];
    title.font = [UIFont systemFontOfSize:20];
    title.text = @"确认订单";
    [navView addSubview:title];
    
    [title makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self->navView.centerX);
        make.centerY.equalTo(backImage.centerY);
    }];
    
    UIView * goodsArea = UIView.new;
    goodsArea.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:goodsArea];
    
    [goodsArea makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.top).offset(height + 10);
        make.left.equalTo(self.view.left).offset(0);
        make.right.equalTo(self.view.right).offset(0);
        make.height.equalTo(80);
    }];
    
    UIView *divideLine2 = UIView.new;
    divideLine2.backgroundColor = UIColorFromRGB(0xDDDDDD) ;
    [self.view addSubview:divideLine2];
    
    [divideLine2 makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(goodsArea.top).offset(0);
        make.left.equalTo(goodsArea.left).offset(0);
        make.right.equalTo(goodsArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    
    UIView *divideLine3 = UIView.new;
    divideLine3.backgroundColor = UIColorFromRGB(0xDDDDDD) ;
    [self.view addSubview:divideLine3];
    
    [divideLine3 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(goodsArea.bottom).offset(0);
        make.left.equalTo(goodsArea.left).offset(0);
        make.right.equalTo(goodsArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    
    UIImageView *goodsImageView = UIImageView.new;
    [goodsArea addSubview:goodsImageView];
    
    [goodsImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(goodsArea.left).offset(10);
        make.top.equalTo(goodsArea.top).offset(10);
        make.width.equalTo(60);
        make.height.equalTo(60);
    }];
    
    [goodsImageView sd_setImageWithURL:[NSURL URLWithString:self.imgUrl ] placeholderImage:[UIImage imageNamed:@"placeholder_600_150"] options:SDWebImageRefreshCached];
    
    UILabel *orderNameLabel = UILabel.new;
    orderNameLabel.text = self.activityTitle;
    orderNameLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:16];
    orderNameLabel.textColor = MAIN_FONT_COLOR;
    orderNameLabel.numberOfLines = 2;
    [goodsArea addSubview:orderNameLabel];
    
    [orderNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(goodsImageView.top).offset(0);
        make.left.equalTo(goodsImageView.right).offset(10);
        make.right.equalTo(goodsArea.right).offset(-10);
    }];
    
    UILabel *priceLabel = UILabel.new;
    priceLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:16];
    priceLabel.textColor = MAIN_COLOR;
    priceLabel.numberOfLines = 1;
    priceLabel.text = @"¥0";
    [goodsArea addSubview:priceLabel];
    
    [priceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(goodsImageView.bottom).offset(0);
        make.left.equalTo(goodsImageView.right).offset(10);
    }];
    
    UILabel *marketPriceLabel = UILabel.new;
    marketPriceLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:13];
    marketPriceLabel.textColor = UIColorFromRGB(0x999999);
    marketPriceLabel.numberOfLines = 1;
    // 中划线
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"市场价：¥%d", self.price]  attributes:attribtDic];
    marketPriceLabel.attributedText = attribtStr;
    [goodsArea addSubview:marketPriceLabel];
    
    [marketPriceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(priceLabel.centerY);
        make.left.equalTo(priceLabel.right).offset(5);
    }];

    
    UIView * addressArea = UIView.new;
    addressArea.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:addressArea];
    
    [addressArea makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(goodsArea.bottom).offset(10);
        make.left.equalTo(self.view.left).offset(0);
        make.right.equalTo(self.view.right).offset(0);
        make.height.equalTo(200);
    }];
    
    UIView *divideLine4 = UIView.new;
    divideLine4.backgroundColor = UIColorFromRGB(0xDDDDDD) ;
    [self.view addSubview:divideLine4];
    
    [divideLine4 makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(addressArea.top).offset(0);
        make.left.equalTo(addressArea.left).offset(0);
        make.right.equalTo(addressArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    UIView *divideLine5 = UIView.new;
    divideLine5.backgroundColor = UIColorFromRGB(0xDDDDDD) ;
    [self.view addSubview:divideLine5];
    
    [divideLine5 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addressArea.bottom).offset(0);
        make.left.equalTo(addressArea.left).offset(0);
        make.right.equalTo(addressArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    UILabel *mobileDescView = UILabel.new;
    mobileDescView.text = @"手机号";
    mobileDescView.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    mobileDescView.textColor = MAIN_FONT_COLOR;
    [addressArea addSubview:mobileDescView];
    
    [mobileDescView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addressArea.top).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
    }];
    
    _mobileTextField = UITextField.new;
    _mobileTextField.placeholder = @"请输入手机号";
    [_mobileTextField setValue:UIColorFromRGB(0xCCCCCC) forKeyPath:@"_placeholderLabel.textColor"];
    _mobileTextField.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    _mobileTextField.textColor = MAIN_FONT_COLOR;
    _mobileTextField.keyboardType = UIKeyboardTypeNumberPad;
    _mobileTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [addressArea addSubview:_mobileTextField];
    
    [_mobileTextField makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(mobileDescView.centerY);
        make.left.equalTo(mobileDescView.right).offset(20);
        make.right.equalTo(self.view.right).offset(-10);
    }];
    
    UserModel *userModel = [[PINCache sharedCache] objectForKey:@"user"];
    _mobileTextField.text = userModel.mobile;
    
    
    UIView *divideLine6 = UIView.new;
    divideLine6.backgroundColor = UIColorFromRGB(0xDDDDDD);
    [addressArea addSubview:divideLine6];
    
    [divideLine6 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(mobileDescView.bottom).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
        make.right.equalTo(addressArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    UILabel *consigneeDescView = UILabel.new;
    consigneeDescView.text = @"收货人";
    consigneeDescView.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    consigneeDescView.textColor = MAIN_FONT_COLOR;
    [addressArea addSubview:consigneeDescView];
    
    [consigneeDescView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(divideLine6.top).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
    }];
    
    _consigneeTextField = UITextField.new;
    _consigneeTextField.placeholder = @"请输入收货人";
    [_consigneeTextField setValue:UIColorFromRGB(0xCCCCCC) forKeyPath:@"_placeholderLabel.textColor"];
    _consigneeTextField.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    _consigneeTextField.textColor = MAIN_FONT_COLOR;
    _consigneeTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [addressArea addSubview:_consigneeTextField];
    
    [_consigneeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(consigneeDescView.centerY);
        make.left.equalTo(consigneeDescView.right).offset(20);
        make.right.equalTo(self.view.right).offset(-10);
    }];
    
//    _consigneeTextField.text = [Global getInstance].user.address.consignee;
    
    UIView *divideLine7 = UIView.new;
    divideLine7.backgroundColor = UIColorFromRGB(0xDDDDDD);
    [addressArea addSubview:divideLine7];
    
    [divideLine7 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(consigneeDescView.bottom).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
        make.right.equalTo(addressArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    UILabel *areaDescView = UILabel.new;
    areaDescView.text = @"所在地区";
    areaDescView.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    areaDescView.textColor = MAIN_FONT_COLOR;
    [addressArea addSubview:areaDescView];
    
    [areaDescView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(divideLine7.top).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
    }];
    
    _areaLabel = UILabel.new;
    _areaLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    _areaLabel.textColor = MAIN_FONT_COLOR;
    [addressArea addSubview:_areaLabel];
    
    [_areaLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(areaDescView.centerY);
        make.left.equalTo(areaDescView.right).offset(20);
        make.right.equalTo(self.view.right).offset(-10);
    }];
    
//    if ([Global getInstance].user.address.province != nil) {
//        _areaLabel.text = [NSString stringWithFormat:@"%@-%@-%@", [Global getInstance].user.address.province, [Global getInstance].user.address.city, [Global getInstance].user.address.district];
//
//        _province = [Global getInstance].user.address.province;
//        _city =  [Global getInstance].user.address.city;
//        _district = [Global getInstance].user.address.district;
//    }
//
    UIImageView *goViewIcon = UIImageView.new;
    goViewIcon.image = [UIImage imageNamed:@"go"];
    [addressArea addSubview:goViewIcon];
    
    [goViewIcon makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(addressArea.right).offset(-10);
        make.centerY.equalTo(areaDescView.centerY);
        make.width.equalTo(10);
        make.height.equalTo(18.5);
    }];
    
    
    UIView *divideLine8 = UIView.new;
    divideLine8.backgroundColor = UIColorFromRGB(0xDDDDDD);
    [addressArea addSubview:divideLine8];
    
    [divideLine8 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(areaDescView.bottom).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
        make.right.equalTo(addressArea.right).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    //地区点击button
    UIButton *areaButton = UIButton.new;
    [areaButton addTarget:self action:@selector(showPickerView) forControlEvents:UIControlEventTouchUpInside];
    [addressArea addSubview:areaButton];
    
    [areaButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(divideLine7.bottom).offset(0);
        make.left.equalTo(addressArea.left).offset(0);
        make.right.equalTo(addressArea.right).offset(0);
        make.bottom.equalTo(divideLine8.top);
    }];
    
    UILabel *addressDescView = UILabel.new;
    addressDescView.text = @"详细地址";
    addressDescView.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    addressDescView.textColor = MAIN_FONT_COLOR;
    [addressArea addSubview:addressDescView];
    
    [addressDescView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(divideLine8.top).offset(15);
        make.left.equalTo(addressArea.left).offset(10);
    }];
    
    _addressTextView = UITextView.new;
    _addressTextView.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    _addressTextView.textColor = MAIN_FONT_COLOR;
    [addressArea addSubview:_addressTextView];
    
    [_addressTextView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addressDescView.top).offset(-8);
        make.left.equalTo(addressDescView.right).offset(20);
        make.right.equalTo(self.view.right).offset(-10);
        make.bottom.equalTo(addressArea.bottom);
    }];
    
//    _addressTextView.text = [Global getInstance].user.address.address;
    
    UIButton *button = UIButton.new;
    button.layer.cornerRadius = 5;
    button.backgroundColor = MAIN_COLOR;
    button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
    [button setTitle:@"确认提交" forState:UIControlStateNormal];
    [button setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:18];
    [button addTarget:self action:@selector(confirmOrder:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    [button makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addressArea.bottom).offset(20);
        make.left.equalTo(self.view.left).offset(20);
        make.right.equalTo(self.view.right).offset(-20);
        make.height.equalTo(40);
    }];
    
    UILabel *tipLabel = UILabel.new;
    tipLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    tipLabel.textColor = MAIN_FONT_COLOR;
    tipLabel.numberOfLines = 0;
    [self.view addSubview:tipLabel];
    
    
//    ConfigModel * config = [ConfigModel getCache];
//    if (config != nil && config.order_confirm_tip != nil) {
//        tipLabel.text = config.order_confirm_tip;
//    }
    
    [tipLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button.bottom).offset(10);
        make.left.equalTo(button.left).offset(0);
        make.right.equalTo(button.right).offset(0);
        
    }];
    
    // 省市区
    _pickerViewArea = UIView.new;
    _pickerViewArea.backgroundColor = [UIColor whiteColor];
    
    UIButton *pickerCancelButton = UIButton.new;
    pickerCancelButton.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    [pickerCancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [pickerCancelButton setTitleColor:MAIN_FONT_COLOR forState:UIControlStateNormal];
    pickerCancelButton.titleLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    [pickerCancelButton addTarget:self action:@selector(hiddenPickerView) forControlEvents:UIControlEventTouchUpInside];
    [_pickerViewArea addSubview:pickerCancelButton];
    
    [pickerCancelButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_pickerViewArea.top).offset(0);
    }];
    
    UIButton *pickerConfirmButton = UIButton.new;
    pickerConfirmButton.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    [pickerConfirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [pickerConfirmButton setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
    pickerConfirmButton.titleLabel.font = [UIFont fontWithName:MAIN_FONT_NAME size:14];
    [pickerConfirmButton addTarget:self action:@selector(pickerConfirm) forControlEvents:UIControlEventTouchUpInside];
    [_pickerViewArea addSubview:pickerConfirmButton];
    
    [pickerConfirmButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_pickerViewArea.top).offset(0);
        make.right.equalTo(self->_pickerViewArea.right).offset(0);
    }];
    
    _pickerView = UIPickerView.new;
    _pickerView.delegate = self;
    [_pickerViewArea addSubview:_pickerView];
    
    [_pickerView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_pickerViewArea.left).offset(0);
        make.right.equalTo(self->_pickerViewArea.right).offset(0);
        make.bottom.equalTo(self->_pickerViewArea.bottom).offset(0);
        make.height.equalTo(216);
    }];
    
    
//    _province = [Global getInstance].user.address.province;
//    _city =  [Global getInstance].user.address.city;
//    _district = [Global getInstance].user.address.district;
//
    
//    if ([Global getInstance].user.address.province != nil) {
//        for (int i=0; i < [_provinceArray count]; i++) {
//            NSString *province = [[_provinceArray objectAtIndex:i] objectForKey:@"name"];
//            if ([province isEqualToString:[Global getInstance].user.address.province]) {
//                [_pickerView selectRow:i inComponent:0 animated:YES];
//                break;
//            }
//        }
//    }
//    
//    if ([Global getInstance].user.address.city != nil) {
//        for (int i=0; i < [_cityArray count]; i++) {
//            NSString *city = [[_cityArray objectAtIndex:i] objectForKey:@"name"];
//            if ([city isEqualToString:[Global getInstance].user.address.city]) {
//                [_pickerView selectRow:i inComponent:1 animated:YES];
//                break;
//            }
//        }
//    }
//    
//    if ([Global getInstance].user.address.district != nil) {
//        for (int i=0; i < [[_districtDic objectForKey:@"area"] count]; i++) {
//            NSString *district = [[_districtDic objectForKey:@"area"] objectAtIndex:i];
//            if ([district isEqualToString:[Global getInstance].user.address.district]) {
//                [_pickerView selectRow:i inComponent:2 animated:YES];
//                break;
//            }
//        }
//    }
}


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
    if (component == 0) {
        return [_provinceArray count];
    } else if (component == 1) {
        return [_cityArray count];
    } else {
        return [[_districtDic objectForKey:@"area"] count];
    }
}


-(NSString *)pickerView:(UIPickerView *)pickerView
            titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (component == 0) {
        NSDictionary *province = [_provinceArray objectAtIndex:row];
        
        NSLog(@"%@", [province objectForKey:@"name"]);
        return [province objectForKey:@"name"];
    } else if (component == 1) {
        NSDictionary *city = [_cityArray objectAtIndex:row];
        return [city objectForKey:@"name"];
    } else {
        NSArray *area = [_districtDic objectForKey:@"area"];
        return [area objectAtIndex:row];
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == 0) {
        _cityArray = [[_provinceArray objectAtIndex:row] objectForKey:@"city"];
        
        [_pickerView reloadComponent:1];
        [_pickerView selectRow:0 inComponent:1 animated:YES];
        
        _districtDic = [_cityArray objectAtIndex:0];
        [_pickerView reloadComponent:2];
        [_pickerView selectRow:0 inComponent:2 animated:YES];
        
    } else if (component == 1) {
        _districtDic = [_cityArray objectAtIndex:row];
        [_pickerView reloadComponent:2];
        [_pickerView selectRow:0 inComponent:2 animated:YES];
    }
}

-(void) initPickerData {
    
    _provinceArray = NSArray.new;
    _cityArray = NSArray.new;
    _districtDic = NSDictionary.new;
    
    NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"address" ofType:@"json"];
    NSData *jsonData = [NSData dataWithContentsOfFile:jsonPath];
    
    NSError *error = nil;
    id  responseObject = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    
    //NSLog(@"%@", responseObject);
    
    if (error) {
        //DLog(@"%@", [error localizedDescription]);
    }else{
        //        DLog(@"json:%@", responseObject);
        NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
        
        [responseObject enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            NSMutableArray *city = [NSMutableArray array];
            [obj[@"city"] enumerateObjectsUsingBlock:^(id  _Nonnull ob, NSUInteger idx, BOOL * _Nonnull stop) {
                
                NSDictionary *dic = (NSDictionary *)ob;
                [city addObject:@{@"name": dic[@"name"],
                                  @"area": [NSArray arrayWithArray:dic[@"area"]]}];
                
            }];
            
            [tmpArray addObject:@{@"name": obj[@"name"],
                                  @"city": city}];
        }];
        
        _provinceArray = [NSArray arrayWithArray:tmpArray];
    }
    

    
    _cityArray = [[_provinceArray objectAtIndex:0] objectForKey:@"city"];
    _districtDic = [_cityArray objectAtIndex:0];
    
    NSLog(@"%@", _districtDic);
}

- (void) showPickerView {
    
    _maskButton = UIButton.new;
    _maskButton.backgroundColor = [UIColor blackColor];
    _maskButton.alpha = 0.0;
    [_maskButton addTarget:self action:@selector(hiddenPickerView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_maskButton];
    
    [_maskButton makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
    _pickerViewArea.frame  = CGRectMake(0, MAIN_SCREEN_HEIGHT, MAIN_SCREEN_WIDTH, ADDRESS_PICKER_HEIGHT);
    [self.view addSubview:_pickerViewArea];
    
    
    [UIView animateWithDuration:0.3 animations:^{
        self->_maskButton.alpha = 0.4;
        self->_pickerViewArea.frame  = CGRectMake(0, MAIN_SCREEN_HEIGHT-ADDRESS_PICKER_HEIGHT, MAIN_SCREEN_WIDTH, ADDRESS_PICKER_HEIGHT);
    }];
    
}

- (void)pickerConfirm {
    
    NSInteger row1 = [_pickerView selectedRowInComponent:0];
    NSInteger row2 = [_pickerView selectedRowInComponent:1];
    NSInteger row3 = [_pickerView selectedRowInComponent:2];
    
    _province = [[_provinceArray objectAtIndex:row1] objectForKey:@"name"];
    _city =  [[_cityArray objectAtIndex:row2] objectForKey:@"name"];
    _district = [[_districtDic objectForKey:@"area"] objectAtIndex:row3];
    
    _areaLabel.text = [NSString stringWithFormat:@"%@-%@-%@", _province, _city, _district];
    
    [self hiddenPickerView];
}

- (void) hiddenPickerView {
    
    [UIView animateWithDuration:0.3 animations:^{
        self->_maskButton.alpha = 0.0;
        self->_pickerViewArea.frame  = CGRectMake(0, MAIN_SCREEN_HEIGHT, MAIN_SCREEN_WIDTH, ADDRESS_PICKER_HEIGHT);
    } completion:^(BOOL finished) {
        [self->_maskButton removeFromSuperview];
        [self->_pickerViewArea removeFromSuperview];
        
    }];
    
}

-(void) btnClick {
    
      [self.navigationController popViewControllerAnimated:YES];
    
}

@end
